#define	_CRT_SECURE_NO_WARNINGS 1 

#include "Queue.h"

void QueueInit(Queue* q)
{
	assert(q);
	q->phead = NULL;
	q->ptail = NULL;
	q->size = 0;
}
void QueuePush(Queue* q, QDataType x)
{
	assert(q);
	QLNode* newnode = (QLNode*)malloc(sizeof(QLNode));
	newnode->next = NULL;
	newnode->val = x;
	if (q->phead == NULL)
	{
		q->phead = q->ptail = newnode;
	}
	else
	{
		q->ptail->next = newnode;
		q->ptail = q->ptail->next;
	}
	q->size++;
}
void QueuePop(Queue* q)
{
	assert(q);
	assert(q->phead != NULL);
	QLNode* tmp = q->phead;
	q->phead = q->phead->next;
	free(tmp);
	if (q->phead == NULL)
	{
		q->ptail = NULL;
	}
	q->size--;
}
QDataType QueueFront(Queue* q)
{
	assert(q);
	return q->phead->val;
}
QDataType QueueBack(Queue* q)
{
	assert(q);
	return q->ptail->val;
}
int QueueSize(Queue* q)
{
	assert(q);
	return q->size;
}
int QueueEmpty(Queue* q)
{
	assert(q);
	if (q->phead == NULL)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
void QueueDestroy(Queue* q)
{
	assert(q);
	QLNode* cur = q->phead;
	while (cur != NULL)
	{
		QLNode* tmp = cur;
		cur = cur->next;
		free(tmp);
	}
	q->phead = NULL;
	q->ptail = NULL;
	q->size = 0;
}